package com.bbx.taxi.client.widget.Dailog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import u.aly.de;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Handler;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.view.Window.Callback;
import android.widget.AdapterView;

import com.bbx.androidapi.util.SharedPreUtil;
import com.bbx.api.gclient.GMsg;
import com.bbx.api.gclient.msg.CouponMsg;
import com.bbx.api.sdk.model.passanger.Return.Coupon.CouponList;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Coupons;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Metadata;
import com.bbx.api.sdk.model.passanger.Return.Coupon.SpecialTime;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Metadata.CarClass;
import com.bbx.api.sdk.model.passanger.Return.ActivityContent;
import com.bbx.api.sdk.model.passanger.Return.Jmsg.Msgs;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrderList;
import com.bbx.api.sdk.model.passanger.Return.PriceAll.PriceAllDetail;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.util.SharedPreEncryptUtil;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.Activity.Base.BaseBBXActivity;
import com.bbx.taxi.client.Activity.Main.IMainContract.SHAREVIEW_TYPE;
import com.bbx.taxi.client.Activity.Main.IMainContract.SHAREVIEW_TYPE2;
import com.bbx.taxi.client.Activity.Main.MainActivity;
import com.bbx.taxi.client.Activity.Main.MainActivity;
import com.bbx.taxi.client.Activity.Order.CancelOrderActivity;
import com.bbx.taxi.client.Activity.Order.OrderEvaluationActivity2;
import com.bbx.taxi.client.Activity.Order.StartServiceActivity;
import com.bbx.taxi.client.Activity.login.LoginActivity;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute.CjType;
import com.bbx.taxi.client.Bean.Extra.MainMsg;
import com.bbx.taxi.client.Bean.Extra.OrderMsg;
import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;
import com.bbx.taxi.client.Service.LoginService;
import com.bbx.taxi.client.Task.MyCancelTask;
import com.bbx.taxi.client.Task.MyOrderWaitTask;
import com.bbx.taxi.client.Util.DataCleanManager;
import com.bbx.taxi.client.Util.DateFormat;
import com.bbx.taxi.client.Util.FormatUtil;
import com.bbx.taxi.client.Util.IsActivityFinishUtils;
import com.bbx.taxi.client.Util.IsSnQiangDan;
import com.bbx.taxi.client.Util.RequestUtils;
import com.bbx.taxi.client.Util.StartOrderUtils;
import com.bbx.taxi.client.Util.ToCity2;
import com.bbx.taxi.client.Util.VersionUtils;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickSingleListener;
import com.bbx.taxi.client.widget.Dailog.MyBusyDailog;
import com.bbx.taxi.client.widget.Dailog.MyChangePriceDialog.onClickChangeLeftListener;
import com.bbx.taxi.client.widget.Dailog.MyChangePriceDialog.onClickChangeRightListener;
import com.bbx.taxi.client.widget.Dailog.MyChangePriceDialog.onClickChangeSingleListener;
import com.bbx.taxi.client.widget.Dailog.MyPayOrderDailog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickLeftListener;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickRightListener;
import com.bbx.taxi.client.widget.Dailog.MyPayOrderDailog.onClickPayListener;
import com.bbx.taxi.client.widget.Dailog.MySaveMoneyDialog.MyOnItemClickListener;
import com.bbx.taxi.client.widget.Dailog.MySnTimeOutDialog.onClickSnLeftListener;
import com.bbx.taxi.client.widget.Dailog.MySnTimeOutDialog.onClickSnRightListener;

/**
 * 消息过来的弹窗类型
 * 
 */
public class MessageDialog {
	static MyEnterCouponDailog mMyEnterCouponDailog;
	public static int max_dialog=15;
	public static Map<String,Integer> map_dialog=new HashMap<String, Integer>();	
	/**
	 *客服取消
	 */
	public synchronized static void onKfCancelDialog(final Activity context,
			final Msgs.Data msgs_data) {
		MyTypeDailog canceldialog = new MyTypeDailog(context);
		canceldialog.setModel(MyTypeDailog.TYPE_CANCEL, msgs_data);
	}
	/**
	 *改派
	 */
	public synchronized static void onGaipaiDialog(final Activity context,
			final Msgs.Data msgs_data) {
		MyTypeDailog gaipaidialog = new MyTypeDailog(context);
		gaipaidialog.setModel(MyTypeDailog.TYPE_GAIPAI, msgs_data);
	}
	
	/**
	 *下车支付
	 */
	public synchronized static void onOffCarDialog(final Activity context,
			final Msgs.Data msgs_data) {
		if (msgs_data != null) {
			new AsyncTask<Void, Void, Void>() {
				MyOrderingDB db_myordering;
				MyOrderList mMyOrderList;
				String order_id;
				String start_city="";
				String end_city="";
				 MyPayOrderDailog payorder_dialog;
				@Override
				protected Void doInBackground(Void... arg0) {
					try{
					order_id = msgs_data.getOrder_id();
					db_myordering = new MyOrderingDB();// 我的进行中的订单数据库
					mMyOrderList = db_myordering
							.onReadDB_ing(order_id);
						start_city = ToCity2.getCity(mMyOrderList
									.getLocations().getStart().getAddress());
						end_city = ToCity2.getCity(mMyOrderList
									.getLocations().getEnd().getAddress());
					}catch(Exception e){}
					return null;
				}

				@Override
				protected void onPostExecute(Void result) {
					 payorder_dialog = new MyPayOrderDailog(
								context);
					payorder_dialog.setOrderId(order_id);
					payorder_dialog.setMoney(FormatUtil
							.onFormatPrice(mMyOrderList.getPrice()));
					payorder_dialog.setContent(String.format(
							context.getString(R.string.order),
							DateFormat.onDateRemove_ss(mMyOrderList
									.getAppoint_time())
									+ "\n"
									+ start_city
									+ context.getString(R.string.to) + end_city));
					if (payorder_dialog != null && !payorder_dialog.isShowing()&&
							start_city!=null&&!start_city.equals("")&&end_city!=null&&!end_city.equals("")) {
						payorder_dialog.show();
					}
					if(IsSnQiangDan.isIncludeSnQiangDanLocal(context)!=null){
						payorder_dialog.setSingle();
					}
					payorder_dialog
							.setOnClickPayListener(new onClickPayListener() {
								@Override
								public void onClickPay() {
									Intent intent = new Intent(context,
											OrderEvaluationActivity2.class);
									intent.putExtra(OrderMsg.order_id_finish,
											order_id);
									intent.putExtra(OrderMsg.finish_type,
											OrderMsg.finish_ing);
									context.startActivity(intent);
								}
							});
					super.onPostExecute(result);
				}

			}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		}
	}
	
	/**
	 * 繁忙
	 */
	public synchronized static void onBusyDialog(final Activity context,
			final Msgs.Data msgs_data) {
		new AsyncTask<Void, Void, Void>() {
			 MyOrderList mMyOrderList;
			 String start_city="";
			 String end_city="";
			@Override
			protected Void doInBackground(Void... arg0) {
				if (msgs_data != null && msgs_data.getText() != null) {
					MyOrderingDB db_myordering = new MyOrderingDB();// 我的进行中的订单数据库
					 mMyOrderList = db_myordering.onReadDB_ing(
							msgs_data.getOrder_id());
					 if(mMyOrderList.getLocations()!=null){
					 start_city = ToCity2.getCity(mMyOrderList.getLocations()
							.getStart().getAddress());
					 end_city = ToCity2.getCity(mMyOrderList.getLocations()
							.getEnd().getAddress());
					 }
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				MyBusyDailog busyDailog = new MyBusyDailog(context);
				if(msgs_data!=null&&msgs_data.getText()!=null){
					busyDailog.setTitle(msgs_data.getText());
					busyDailog.setContent(DateFormat.onDateRemove_ss(mMyOrderList
							.getAppoint_time())
							+ "\n"
							+ start_city
							+ "→"
							+ end_city);
					if (busyDailog != null && !busyDailog.isShowing()) {
						busyDailog.show();
					}
				}	
				super.onPostExecute(result);
			}
			
		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		
		
		
	}
	/**
	 * 重登
	 */
	public synchronized static void onReloginDialog(final Activity context){
		context.stopService(new Intent(context, LoginService.class));
		MyAlertDailog dialog = new MyAlertDailog(context);
		dialog.setTitle(context.getString(R.string.mydailog_title));
		dialog.setContent(context.getString(R.string.mydailog_content_login));
		dialog.setLeftButtonText(context.getString(R.string.mydailog_exit));
		dialog.setRightButtonText(context.getString(R.string.mydailog_relogin));
		if (dialog != null && !dialog.isShowing()) {
			dialog.show();
		}
		dialog.setOnClickLeftListener(new onClickLeftListener() {
			@Override
			public void onClickLeft() {
				MyApplication.getInstance().exit();
				DataCleanManager.cleanDatabases(context);
				DataCleanManager.cleanSharedPreference(context);
				context.finish();
			}
		});
		dialog.setOnClickRightListener(new onClickRightListener() {

			@Override
			public void onClickRight() {
				Intent intent = new Intent();
				intent.setClass(context, LoginActivity.class);
				context.startActivity(intent);
			}
		});
	}
	/**
	 * 重登2
	 */
	public synchronized static void onReloginDialog2(final Activity context){
		context.stopService(new Intent(context, LoginService.class));
		MyAlertDailog dialog = new MyAlertDailog(context);
		Resources res = context.getResources();
		dialog.setTitle(res.getString(R.string.mydailog_title));
		dialog.setContent(res.getString(R.string.mydailog_content_login));
		dialog.setLeftButtonText(res.getString(R.string.mydailog_exit));
		dialog.setRightButtonText(res.getString(R.string.mydailog_relogin));
		if (dialog != null && !dialog.isShowing()) {
			dialog.show();
		}
		dialog.setOnClickLeftListener(new onClickLeftListener() {
			@Override
			public void onClickLeft() {
				MyApplication.getInstance().exit();
				context.stopService(new Intent(context, LoginService.class));
				DataCleanManager.cleanDatabases(context);
				DataCleanManager.cleanSharedPreference(context);
				Intent intent = new Intent(context, MainActivity.class);
				intent.putExtra(MainMsg.extra_quit, MainMsg.INTENT_QUIT);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				context.startActivity(intent);
				context.overridePendingTransition(0, 0);
				context.finish();
				context.overridePendingTransition(0, 0);
			}
		});
		dialog.setOnClickRightListener(new onClickRightListener() {

			@Override
			public void onClickRight() {
				Intent intent = new Intent();
				intent.setClass(context, LoginActivity.class);
				context.startActivity(intent);
			}
		});
	}
	public synchronized static void onEnterCouponDialog(final Activity context,
			final JSONObject jb){
		new AsyncTask<Void, Void, Void>() {
			CouponList mCouponList;
			@Override
			protected Void doInBackground(Void... arg0) {
				mCouponList= new CouponList();
				JSONArray ja_CouponList;
				try {
					List<Coupons> coupons_list = new ArrayList<Coupons>();
					JSONObject jmsg = jb.getJSONObject(GMsg.msg_jmsg);
					JSONObject jmsg_data =null;
					try{
						 jmsg_data = new JSONObject(jmsg.getString(GMsg.msg_data));
					}catch(Exception e){
						//报错则为离线消息
						JSONArray msgs = jmsg.getJSONArray(GMsg.msg_msgs);
						if (msgs != null && msgs.length() >= 1) {
							JSONObject jo = new JSONObject(msgs.get(0).toString());
							jmsg_data = new JSONObject(jo.getString(GMsg.msg_data));
						}
					}
					
					ja_CouponList = jmsg_data.getJSONArray(GMsg.msg_list);
					for (int i = 0; i < ja_CouponList.length(); i++) {
						Coupons mCoupons = new Coupons();
						JSONObject jo = new JSONObject(ja_CouponList.get(i)
								.toString());
						try{mCoupons.setSum(Integer.parseInt(jo.getString(CouponMsg.msg_sum)));}catch(Exception e){}
						try{mCoupons.setTag(jo.getString(CouponMsg.msg_tag));}catch(Exception e){}
						try{mCoupons.setType(Integer.parseInt(jo.getString(CouponMsg.msg_type)));}catch(Exception e){}
						try{mCoupons.setExpire_time(jo.getString(CouponMsg.msg_expire_time));}catch(Exception e){}
						//起始时间
						try {mCoupons.setEnable_time(jo.getString(CouponMsg.msg_enable_time));} catch (Exception e) {}
						try {mCoupons.setUseLimit(jo.getString(CouponMsg.mgs_use_limit));} catch (Exception e) {
						}
						//赠送者
						try {
							mCoupons.setGifter(jo.getString(CouponMsg.mgs_gifter));
						} catch (Exception e) {
						}
						//赠送时间
						try {
							mCoupons.setGift_time(jo.getString(CouponMsg.mgs_gift_time));
						} catch (Exception e) {
						}
						try{
						JSONObject jo_metadata = new JSONObject(
								jo.getString(CouponMsg.msg_metadata));
						Metadata mMetadata = new Metadata();	      
						try{
							JSONArray ja_line =new JSONArray(jo_metadata.getString(CouponMsg.msg_usableline));
							List<String> list_line=new ArrayList<String>();
							for(int j=0;j<ja_line.length();j++){
								String str_line=ja_line.get(j).toString();
								list_line.add(str_line);
							}
							mMetadata.setUsableline(list_line);
						}catch(Exception e){
							List<String> list_line=new ArrayList<String>();
							list_line.add(jo_metadata.getString(CouponMsg.msg_usableline));
							mMetadata.setUsableline(list_line);
						}
						
						try{mMetadata.setUsabletype(jo_metadata
								.getString(CouponMsg.msg_usabletype));}catch(Exception e){}
						try{mMetadata.setUsableorder(jo_metadata
								.getString(CouponMsg.msg_usableorder));}catch(Exception e){}
						try{mMetadata.setUsabletime(jo_metadata
								.getString(CouponMsg.msg_usabletime));}catch(Exception e){}
						try{mMetadata.setSum_low_limit(jo_metadata
									.getString(CouponMsg.msg_sum_low));}catch(Exception e){}
						try {
							mMetadata.setBusinessType(jo_metadata
									.getString(CouponMsg.mgs_business_type));
						} catch (Exception e) {
						}
						//车型
						try {
							JSONArray ja_car = new JSONArray(
									jo_metadata.getString(CouponMsg.mgs_car_class));
							List<CarClass> list_car = new ArrayList<CarClass>();
							if(ja_car.toString().contains("*")){
								CarClass carclass=new Metadata().new CarClass();
								carclass.setName("*");
								list_car.add(carclass);
							}else{
								for (int j = 0; j < ja_car.length(); j++) {
									JSONObject jo_car = new JSONObject(ja_car.get(j).toString());
									CarClass carclass=new Metadata().new CarClass();
									carclass.setId(jo_car.getString(CouponMsg.mgs_car_id));
									carclass.setName(jo_car.getString(CouponMsg.mgs_car_name));
									list_car.add(carclass);
								}
							}
							mMetadata.setCarClass(list_car);
						
						} catch (Exception e) {
						}
//						//周几限制
//						try {
//							JSONArray ja_time_limit = new JSONArray(
//									jo_metadata.getString(CouponMsg.msg_time_week_use));
//							List<String> list_time_limit = new ArrayList<String>();
//							for (int j = 0; j < ja_time_limit.length(); j++) {
//								String str_time_limit = ja_time_limit.get(j).toString();
//								list_time_limit.add(str_time_limit);
//							}
//							mMetadata.time_week_use=list_time_limit;
//						} catch (Exception e) {
//						}
//						//特殊限制，如周几到周几
//						try{
//							JSONObject json_special = new JSONObject(jo_metadata.getString(CouponMsg.msg_special_time_nouse));
//							SpecialTime mSpecialTime=new SpecialTime();
//							mSpecialTime.start_time=json_special.getLong(CouponMsg.msg_start_time);
//							mSpecialTime.end_time=json_special.getLong(CouponMsg.msg_end_time);
//							mMetadata.special_time_nouse=mSpecialTime;
//						}catch(Exception e){}
						mCoupons.setMetadata(mMetadata);
						}
						catch(Exception e){
						}
						coupons_list.add(mCoupons);
					}
					mCouponList.setCouponList(coupons_list);
				} catch (JSONException e) {
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				if(mCouponList.getCouponList()==null){
					return ;
				}
				if(mMyEnterCouponDailog!=null){
					if(!mMyEnterCouponDailog.isShowing()){
						mMyEnterCouponDailog.show();
						mMyEnterCouponDailog.setList(mCouponList.getCouponList());
					}else{
						mMyEnterCouponDailog.setList(mCouponList.getCouponList());
					}
				}else{
					mMyEnterCouponDailog=new MyEnterCouponDailog(context);
					mMyEnterCouponDailog.show();
					mMyEnterCouponDailog.setList(mCouponList.getCouponList());
				}

				if(mMyEnterCouponDailog!=null){
					mMyEnterCouponDailog.setOnDismissListener(new OnDismissListener() {
						
						@Override
						public void onDismiss(DialogInterface dialog) {
							mMyEnterCouponDailog=null;
						}
					});
				}
				super.onPostExecute(result);
			}
			
		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
     } 
	/**
	 * 活动
	 */
	public synchronized static void onActivityDialog(final Activity context,Object object,boolean isShow){
		if(object!=null){
		ActivityContent mActivityContent=(ActivityContent)object;
		MyActivityDetailsDialog dialog = new MyActivityDetailsDialog(context);
		dialog.setContent(mActivityContent);
		long time=SharedPreUtil.getLongValue(context,SharedPreEncryptUtil.activity_show_time, 0);
		long interval=SharedPreUtil.getLongValue(context,SharedPreEncryptUtil.activity_interval, 0);
		long current_time=System.currentTimeMillis();
		if (dialog != null && !dialog.isShowing()&&(current_time-time>interval*1000||isShow)
				&&mActivityContent!=null&&!mActivityContent.getList().isEmpty()) {
			dialog.show();
			SharedPreUtil.putLongValue(context,
					SharedPreEncryptUtil.activity_show_time,System.currentTimeMillis());
		 }		
		}
	}
	/**
	 * AA
	 */
	public synchronized static void onAADialog(final Activity context,
			final Msgs.Data msgs_data) {
		MyAlertDailog dailog = new MyAlertDailog(context);
		if (msgs_data != null && msgs_data.getContent() != null) {
			dailog.setHtml(msgs_data.getContent());
			dailog.setSingle(context.getString(R.string.mydailog_know));
			if (dailog != null && !dailog.isShowing()) {
				dailog.show();
			}
		}
	}
	/**
	 * 市内订单超时
	 */
	public synchronized static MySnTimeOutDialog onSnTimeDialog(final Activity context,
			final Msgs.Data msgs_data) {
        	MySnTimeOutDialog	mMySnTimeOutDialog=new MySnTimeOutDialog(context);
		if (msgs_data != null && msgs_data.getOrder_id() != null) {
			MyOrderingDB db_myordering = new MyOrderingDB();// 我的进行中的订单数据库
			MyOrderList mMyOrderList = db_myordering
					.onReadDB_ing( msgs_data.getOrder_id());
			mMySnTimeOutDialog.setStart(mMyOrderList.getLocations().getStart().getAddress());
			mMySnTimeOutDialog.setEnd(mMyOrderList.getLocations().getEnd().getAddress());
			mMySnTimeOutDialog.setTime(mMyOrderList.getAppoint_time());
			mMySnTimeOutDialog.setonClickSnLeftListener(new onClickSnLeftListener() {
				@Override
				public void onClickSnLeft() {
					RequestUtils.requestCancel(context, msgs_data.getOrder_id());
//					context.startActivityForResult(new Intent(context, CancelOrderActivity.class).putExtra(
//						OrderMsg.cancel_order_id, msgs_data.getOrder_id()), BaseBBXActivity.requestCode);
				}
			});
			mMySnTimeOutDialog.setonClickSnRightListener(new onClickSnRightListener() {
				
				@Override
				public void onClickSnRight() {
					RequestUtils.requestWait(context, msgs_data.getOrder_id());
				}
			});
			
			if (mMySnTimeOutDialog != null && !mMySnTimeOutDialog.isShowing()) {
				mMySnTimeOutDialog.show();
			}
		}
		return mMySnTimeOutDialog;
	}
	
	static MySaveMoneyDialog mMySaveMoneyDialog;
	/**
	 * 省钱
	 */
	public synchronized static boolean onSaveMoneyDialog(final Activity context,
			final List<PriceAllDetail> detail,final MainActivity mainactivity) {
		boolean isSn=false;//判断是否有市内
		final MainAttribute main=MainAttribute.getInstance();
		if(mMySaveMoneyDialog==null)
			mMySaveMoneyDialog= new MySaveMoneyDialog(context);
		
		List<String> list=new ArrayList<String>();
		final List<Integer> lits_type=new ArrayList<Integer>();
		mMySaveMoneyDialog.setCancelable(true);
		if(detail!=null&&!detail.isEmpty()){
			for(int i=0;i<detail.size();i++){
				int type=detail.get(i).type;
				int incity=detail.get(i).incity;
				lits_type.add(type);
				String title="";
				switch (type) {
				case Value.ORDER_TYPE_SN:
					isSn=true;
					list.add(context.getString(R.string.savemoney_sn));
					break;
				case Value.ORDER_TYPE_PC:
					title=String.format(context.getString(R.string.savemoney_pc), FormatUtil.onFormatPrice(detail.get(i).price));
					list.add(title);
					break;
				case Value.ORDER_TYPE_BC:
					title=String.format(context.getString(R.string.savemoney_bc), FormatUtil.onFormatPrice(detail.get(i).price));
					list.add(title);
					break;
				case Value.ORDER_TYPE_KJ:
					title=String.format(context.getString(R.string.savemoney_kj), FormatUtil.onFormatPrice(detail.get(i).price));
					list.add(title);
					break;
				default:
					break;
				 }
			}
			mMySaveMoneyDialog.setList(list,lits_type);
			if (mMySaveMoneyDialog != null && !mMySaveMoneyDialog.isShowing()&&!lits_type.isEmpty()) {
				if(lits_type.size()==1&&lits_type.get(0)==Value.ORDER_TYPE_SN){
					mMySaveMoneyDialog.dismiss();
                     new Handler().postDelayed(new Runnable() {
						
						@Override
						public void run() {
							if(!mainactivity.mPresenter.isCity())return;
							mMySaveMoneyDialog.show();
						}
					}, 1000);
				   //则只有一个市内，不弹窗	
				}else{
					new Handler().postDelayed(new Runnable() {
						
						@Override
						public void run() {
							if(!mainactivity.mPresenter.isCity())return;
							mMySaveMoneyDialog.show();
						}
					}, 1000);
				
				}
				
			}
			mMySaveMoneyDialog.setOnItemClickListener(new MyOnItemClickListener() {
				
				@Override
				public void onItemClick(AdapterView<?> parent, View view, int position,
						long id) {
					int type=lits_type.get(position);
					MainAttribute.getInstance().isStartRecommend=false;
					MainAttribute.getInstance().isEndRecommend=false;
					switch (type) {
					case Value.ORDER_TYPE_SN:
						break;
					case Value.ORDER_TYPE_PC:
						new Handler().postDelayed(new Runnable() {
							@Override
							public void run() {
								//取消获取价格，在获取推荐上车点的目的地的时候会开启可获取价格
								mainactivity.mPresenter.setIsPrice(false);
								main.onSnToCJ();
								main.setCjType(CjType.PC);
								if(mainactivity.gbSlideBar!=null){
									mainactivity.gbSlideBar.setCurrentItem(Value.VIEWID_PC);
								}
								mainactivity.mPresenter.shareView(SHAREVIEW_TYPE.pc,SHAREVIEW_TYPE2.time);
								new Handler().postDelayed(new Runnable() {
									
									@Override
									public void run() {
										mainactivity.mPresenter.setRecommend(true);
										mainactivity.mPresenter.setRecommend(false);
									}
								}, 500);
							}
						}, 0);
						
						break;
					case Value.ORDER_TYPE_BC:
						new Handler().postDelayed(new Runnable() {
							@Override
							public void run() {
								//取消获取价格，在获取推荐上车点的目的地的时候会开启可获取价格
								mainactivity.mPresenter.setIsPrice(false);
								main.onSnToCJ();
								main.setCjType(CjType.BC);
								if(mainactivity.gbSlideBar!=null){
									mainactivity.gbSlideBar.setCurrentItem(Value.VIEWID_PC);
								}
								mainactivity.mPresenter.shareView(SHAREVIEW_TYPE.pc,SHAREVIEW_TYPE2.time);
		                        new Handler().postDelayed(new Runnable() {
									
									@Override
									public void run() {
										mainactivity.mPresenter.setRecommend(true);
										mainactivity.mPresenter.setRecommend(false);
									}
								}, 1000);
							}
						}, 0);
						break;
					case Value.ORDER_TYPE_KJ:
						new Handler().postDelayed(new Runnable() {
							@Override
							public void run() {
								//取消获取价格，在获取推荐上车点的目的地的时候会开启可获取价格
								mainactivity.mPresenter.setIsPrice(false);
								main.onSnToCJ();
								if(mainactivity.gbSlideBar!=null){
									mainactivity.gbSlideBar.setCurrentItem(Value.VIEWID_KJ);
								}
								mainactivity.mPresenter.shareView(SHAREVIEW_TYPE.kj,SHAREVIEW_TYPE2.start);
		                        new Handler().postDelayed(new Runnable() {
									
									@Override
									public void run() {
										mainactivity.mPresenter.setRecommend(true);
										mainactivity.mPresenter.setRecommend(false);
									}
								}, 500);
							}
						}, 0);
						break;
					default:
						break;
					 }
				}
			});
		}
		return isSn;
	}
	/**
	 * 跳转到市内抢单页面
	 */
	public synchronized static void onSnQiangDanDialog(final Activity context,final String order_id,boolean isTanchuang,String title) {
		if(isTanchuang){
			 MyAlertDailog snqiangdandailog = new MyAlertDailog(context);
				snqiangdandailog.setContent(title);
				snqiangdandailog.setCancelable(false);
				snqiangdandailog.setSingle("查看");
				snqiangdandailog.setOnClickSingleListener(new onClickSingleListener() {
					
					@Override
					public void onClickSingle() {
						Intent intent = new Intent(context,
								StartServiceActivity.class);
						intent.putExtra(OrderMsg.extra_type, 1);
						intent.putExtra(OrderMsg.extra_order_id,order_id);
						context.startActivity(intent);
					}
				});
				if (order_id != null && !order_id.equals("")) {
					if (snqiangdandailog != null && !snqiangdandailog.isShowing()) {
						snqiangdandailog.show();
					}
				}
		}else{
			Intent intent = new Intent(context,
					StartServiceActivity.class);
			intent.putExtra(OrderMsg.extra_type, 1);
			intent.putExtra(OrderMsg.extra_order_id, order_id);
			context.startActivity(intent);
		}

		
	}
	

	/**
	 * 改单跟改价
	 */
	public synchronized static void onChangeDialog(final Activity context,int type,final Msgs.Data msgs_data) {
		onChangeDialog( context,type,msgs_data,true);
	}
	public synchronized static void onChangeDialog(final Activity context,int type,final Msgs.Data msgs_data,boolean isDouble) {
			 MyChangePriceDialog changedailog = new MyChangePriceDialog(context);
			 if (msgs_data != null && msgs_data.getOrder_id() != null) {
					MyOrderingDB db_myordering = new MyOrderingDB();// 我的进行中的订单数据库
					final MyOrderList mMyOrderList = db_myordering
							.onReadDB_ing( msgs_data.getOrder_id());
                   if(type==GMsg.ONLINE_KF_CHANGE_ORDER){
                	   changedailog.setTitle(context.getString(R.string.msg_change_order_title));
   					   changedailog.setContent(context.getString(R.string.msg_change_order_cotent));
    				   changedailog.setCount(msgs_data.order_type,msgs_data.count+"");
                   }else if(type==GMsg.ONLINE_KF_CHANGE_PRICE){
                	   changedailog.setTitle(context.getString(R.string.msg_change_price_title));
   					   changedailog.setContent(Html.fromHtml(String.format(context.getString(R.string.msg_change_price_cotent)
   							   ,"<font color=\"#FF0000\">"+FormatUtil.onFormatPrice(msgs_data.old_price)+"元"+"</font>","<font color=\"#FF0000\">"+FormatUtil.onFormatPrice(msgs_data.new_price)+"元"+"</font>")));
   					  changedailog.setCount(mMyOrderList.getOrder_type(),mMyOrderList.getLocations().getCount()+"");
                   }else if(type==GMsg.ONLINE_KF_CHANGE_PRICE2){
               		   String old_mile_price="<font color=\"#FF0000\">"+FormatUtil.onFormatPrice(msgs_data.old_mile_price)+"元"+"</font>";
               		   String new_mile_price="<font color=\"#FF0000\">"+FormatUtil.onFormatPrice(msgs_data.new_mile_price)+"元"+"</font>";
               		   String old_time_price="<font color=\"#FF0000\">"+FormatUtil.onFormatPrice(msgs_data.old_time_price)+"元"+"</font>";
               		   String new_time_price="<font color=\"#FF0000\">"+FormatUtil.onFormatPrice(msgs_data.new_time_price)+"元"+"</font>";
                	   changedailog.setTitle(context.getString(R.string.msg_change_price_title));
   					   changedailog.setContent(Html.fromHtml(String.format(context.getString(R.string.msg_change_price_cotent2),old_mile_price,new_mile_price,old_time_price,new_time_price)));
   					  changedailog.setCount(mMyOrderList.getOrder_type(),mMyOrderList.getLocations().getCount()+"");
                   
                   }else{
//                	   ONLINE_KF_CHANGE 
                	   //则不显示
                	   return;
                   }
                 	changedailog.setContent2(context.getString(R.string.msg_change_tel));             
					changedailog.setStart(mMyOrderList.getLocations().getStart().getAddress());
					changedailog.setEnd(mMyOrderList.getLocations().getEnd().getAddress());
					changedailog.setTime(mMyOrderList.getAppoint_time());
					if(isDouble){
						changedailog.setLeftButtonText(context.getString(R.string.mydailog_go_see));
						changedailog.setRightButtonText(context.getString(R.string.mydailog_no_see));
						changedailog.setOnClickLeftListener(new onClickChangeLeftListener() {
							@Override
							public void onClickLeft() {
								StartOrderUtils.onStartOrder(context,mMyOrderList.getOrder_status(), mMyOrderList.getOrder_id(),BaseBBXActivity.requestCode);
							}
						});
						changedailog.setOnClickRightListener(new onClickChangeRightListener() {
							
							@Override
							public void onClickRight() {
								
							}
						});
					}else{
						changedailog.setSingle(context.getString(R.string.mydailog_know));
					}
				
					
					if (changedailog != null && !changedailog.isShowing()) {
						changedailog.show();
					}
				}
		
	}
	public synchronized static void onThanksFeeDialog(final Activity context,double thanks_fee) {
		MyThanksFeeDailog dailog = new MyThanksFeeDailog(context);
		switch(VersionUtils.getVersionType(context)){
			case bbx:
				dailog.setContent( Html.fromHtml(String.format(context.getString(R.string.thanks_fee_remind), "<font color=\"#FF4343\">" + FormatUtil.onFormatPrice(thanks_fee) +"元"+ "</font>")));
				break;
			case tianshang:
				dailog.setContent( Html.fromHtml(String.format(context.getString(R.string.thanks_fee_remind2), "<font color=\"#FF4343\">" + FormatUtil.onFormatPrice(thanks_fee) +"元"+ "</font>")));
				break;
		}
		if (dailog != null && !dailog.isShowing()) {
			dailog.show();
		}
	}
	public static void clear(){
		mMyEnterCouponDailog=null;
		map_dialog.clear();
		mMySaveMoneyDialog=null;
	}
}
